package com.fit.pages.car;

import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.beans.CarBean;
import com.fit.interfaces.Car;
import com.fit.service.Cars;

public class AddCar {

	@Property
	@Persist("flash")
	private String msg;
	
	@Property
	@Persist("flash")
	private Car car;
	
	@Inject
	private Cars cars;
	
	@SetupRender
	public void onCreateObject(){
		this.car = new CarBean();
	}
	
	void onSuccess(){
		if(car.getCompanyName() != null && car.getModelName() != null){
			cars.save(car);
			this.msg = "you've successfully added car:"  + car.getCompanyName()+"," + car.getModelName();
		}else{
			msg = "WRONG INPUT";
		}
	}
}
